package com.cloud.feeling.ststem.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.common.RestCode;
import com.cloud.common.RestResponse;
import com.cloud.common.model.Menu;
import com.cloud.common.model.User;
import com.cloud.feeling.ststem.service.MenuService;

/**
 * 
  * @Description: 菜单管理控制器
  * @author: feelj
  * @date: 2018年10月22日 下午2:27:31 
  *
 */
@Controller
@RequestMapping
public class MenuController {
	
	@Autowired
	MenuService menuService;
	
	@GetMapping("/menu")
	public String menu() {
		return "menu/menulist";
	}
	
	@PostMapping("/menulist")
	@ResponseBody
	public List<Menu> getMenuList(Integer id){
		return menuService.getMenuList(id);
	}
	
	@GetMapping("/editmenu")
	public String edituser(Menu menu,Model model) {
		List<Menu> selectByMenu = menuService.selectByMenu(menu);
		model.addAttribute("menu",selectByMenu.get(0));
		return "/menu/editmenu";
	}
	
	@GetMapping("/addchildrendmenu")
	public String addchildrendmenu(Menu menu,Model model) {
		List<Menu> selectByMenu = menuService.selectByMenu(menu);
		model.addAttribute("menu",selectByMenu.get(0));
		return "/menu/addchildrendmenu";
	}
	
	@GetMapping("/addmenu")
	public String addmenu() {
		return "/menu/addmenu";
	}
	
	@PostMapping("/saveMenu")
	@ResponseBody
	public RestResponse<RestCode> saveMenu(Menu menu){
		menuService.saveMenu(menu);
		return RestResponse.success();
	}
	
	@PostMapping("/deletemenu")
	@ResponseBody
	public RestResponse<RestCode> deletemenu(Integer id){
		menuService.deleteMenu(id);
		return RestResponse.success();
	}

}
